//
//  MoreView.m
//  AsyncImages
//
//  Created by Matthew on 11-9-24.
//  Copyright 2011年 develop4u.gr. All rights reserved.
//

#import "MoreView.h"

#define INFO_TABLE_WIDTH 320
#define INFO_TABLE_HEIGHT 365

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480

#define TABLE_ROW_HEIGHT 66

@implementation MoreView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        self.backgroundColor = [UIColor whiteColor];

        topBar = [[TopBar alloc] initWithFrame:CGRectMake(0, 0, INFO_TABLE_WIDTH,65)];
        topBar.suffix = @"MORE_VIEW";
        topBar.useReturnBtn = FALSE;
        [topBar initUI:@"筑龙建筑画报" logoDisplay:TRUE type:3];
        [self addSubview:topBar];
        
        infoTable = [[XMLTable alloc] initWithFrame:CGRectMake(0,topBar.frame.size.height, INFO_TABLE_WIDTH, INFO_TABLE_HEIGHT)];
        [self addSubview:infoTable];
        
        infoTable.suffix = @"MORE_VIEW";
        [infoTable configMsg];
        
        [infoTable setAtomData:@"/feed/tag"
                          atom:@"tag"
                          feed:@"feed"];

        [infoTable configTable:INFO_TABLE_WIDTH
                        tableHeight:INFO_TABLE_HEIGHT
                         tableWidth:TABLE_ROW_HEIGHT
                     tableUnitStyle:2];

        [infoTable triggerByURL:@"http://www.emilmatthew.com/xml/more.xml" useFeatureImg:FALSE];
        
        suffix = @"MORE_VIEW";
        detail_panel_shift_in = [[NSString alloc] initWithFormat:@"detail_panel_shift_in_%@",suffix];
        unit_trigger = [[NSString alloc] initWithFormat:@"unit_trigger_%@",suffix];
        detail_panel_shift_out = [[NSString alloc] initWithFormat:@"detail_panel_shift_out_%@",suffix];
        detail_view_exit = [[NSString alloc] initWithFormat:@"detail_view_exit_%@",suffix];
        page_refresh = [[NSString alloc] initWithFormat:@"page_refresh_%@",suffix];
        share_btn_trigger = [[NSString alloc] initWithFormat:@"share_btn_trigger_%@",suffix];
        
        tween_table_suffix = [[NSString alloc] initWithFormat:@"%@%@",suffix,@"tween_table"];

        detailPanel = [[BaseDetailPanel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [detailPanel trigger: @""
                infoBarTitle:@""
                      suffix:suffix];
        [detailPanel closeShareBtn];
        [self addSubview:detailPanel];
        
        loginPanel = [[LoginPanel alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        
        img5_2 = [[UIImageLayer alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
        [img5_2 initImage:@"5_2.png" useOriginalSize:TRUE ratioMode:TRUE layerInfo:Nil];

        img5_3 = [[UIImageLayer alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
        [img5_3 initImage:@"5_3.png" useOriginalSize:TRUE ratioMode:TRUE layerInfo:Nil];
        
        img5_4 = [[UIImageLayer alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
        [img5_4 initImage:@"5_4.png" useOriginalSize:TRUE ratioMode:TRUE layerInfo:Nil];
        
        // Initialization message listener
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:detail_panel_shift_in object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:detail_panel_shift_out object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:unit_trigger object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:detail_view_exit object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:page_refresh object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:share_btn_trigger object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:unit_trigger_tween object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:detail_view_exit_tween object:Nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"login_success" object:Nil];
    }
    return self;
}

-(void) notificationSelector:(NSNotification *) notification
{
    NSString *curNotificationName = [notification name];
    
    if ([curNotificationName isEqualToString:detail_panel_shift_in] ||
        [curNotificationName isEqualToString:unit_trigger])
    {
        NSLog(@"~~detail panel shift in%@",curNotificationName);
        
         MWFeedItem *tempAtom = [notification object];
        
        if ([tempAtom.identifier isEqualToString:@"1"]) 
        {
            [detailPanel setUpTitle:@"用户登陆"];
            [detailPanel addSubview:loginPanel];
            loginPanel.frame = CGRectMake(0, 65, loginPanel.frame.size.width, loginPanel.frame.size.height);
        }
        else if ([tempAtom.identifier isEqualToString:@"2"]) 
        {
            [detailPanel setUpTitle:@"发表作品"];
            [detailPanel addSubview:img5_2];
            img5_2.frame = CGRectMake(0, 65, img5_2.frame.size.width, img5_2.frame.size.height);
        }
        else if ([tempAtom.identifier isEqualToString:@"3"]) 
        {
            [detailPanel setUpTitle:@"更多筑龙产品"];
            [detailPanel addSubview:img5_3];
            img5_3.frame = CGRectMake(0, 65, img5_3.frame.size.width, img5_3.frame.size.height);
        }
        else if ([tempAtom.identifier isEqualToString:@"4"]) 
        {
            [detailPanel setUpTitle:@"关于筑龙网"];
            [detailPanel addSubview:img5_4];
            img5_4.frame = CGRectMake(0, 65, img5_4.frame.size.width, img5_4.frame.size.height);
        }
        else
        {
            return;
        }

        [UIView transitionWithView:detailPanel  duration:0.4f 
                           options:UIViewAnimationCurveEaseOut  
                        animations:
         ^{
             detailPanel.transform = CGAffineTransformMakeTranslation(-SCREEN_WIDTH,0);
             
         }
                        completion:NULL];
    }
    else if ([curNotificationName isEqualToString:detail_panel_shift_out] ||
             [curNotificationName isEqualToString:detail_view_exit] ||
            [curNotificationName isEqualToString: @"login_success"])
    {

        [UIView transitionWithView:detailPanel duration:0.4f 
                           options:UIViewAnimationCurveEaseOut  
                        animations:
         ^{
             detailPanel.transform = CGAffineTransformMakeTranslation(0,0);
             [infoTable releaseSelectedNode];

         }
         completion:NULL];  

    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [super dealloc];
}

@end
